package com.ruoyi.project.demo.type.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.demo.type.domain.GoodType;
import com.ruoyi.project.demo.type.service.IGoodTypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 图书类型Controller
 * 
 * @author demo
 * @date 2020-04-13
 */
@Controller
@RequestMapping("/demo/type")
public class GoodTypeController extends BaseController
{
    private String prefix = "demo/type";

    @Autowired
    private IGoodTypeService goodTypeService;

    @RequiresPermissions("demo:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询图书类型列表
     */
    @RequiresPermissions("demo:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodType goodType)
    {
        startPage();
        List<GoodType> list = goodTypeService.selectGoodTypeList(goodType);
        return getDataTable(list);
    }

    /**
     * 导出图书类型列表
     */
    @RequiresPermissions("demo:type:export")
    @Log(title = "图书类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodType goodType)
    {
        List<GoodType> list = goodTypeService.selectGoodTypeList(goodType);
        ExcelUtil<GoodType> util = new ExcelUtil<GoodType>(GoodType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 新增图书类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存图书类型
     */
    @RequiresPermissions("demo:type:add")
    @Log(title = "图书类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodType goodType)
    {
        return toAjax(goodTypeService.insertGoodType(goodType));
    }

    /**
     * 修改图书类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GoodType goodType = goodTypeService.selectGoodTypeById(id);
        mmap.put("goodType", goodType);
        return prefix + "/edit";
    }

    /**
     * 修改保存图书类型
     */
    @RequiresPermissions("demo:type:edit")
    @Log(title = "图书类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodType goodType)
    {
        return toAjax(goodTypeService.updateGoodType(goodType));
    }

    /**
     * 删除图书类型
     */
    @RequiresPermissions("demo:type:remove")
    @Log(title = "图书类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(goodTypeService.deleteGoodTypeByIds(ids));
    }
}
